package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 李志红
 */
@Api(value = "购物车操作")
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService service;

    @ApiOperation(value = "查询购物车清单")
    @GetMapping("/list")
    public Result<Object> list(){
        List<ShoppingCart> carts = service.getAll();
        return Result.success(carts);
    }

    @ApiOperation(value = "添加购物车")
    @PostMapping("/add")
    public Result<Object> addShoppingCart(@RequestBody ShoppingCartDTO dto){
        service.addCart(dto);

        return Result.success();
    }

    @ApiOperation(value = "清空购物车")
    @DeleteMapping("/clean")
    public Result<Object> subCart(){
        service.clearShoppingCart();
        return Result.success();
    }





}
